Questions
9 of 30
1How can you centre text vertically and horizontally inside a box?
2What is the use of the white-space property?
3How can you truncate text with an ellipsis (...) in CSS?
4How do you wrap or prevent wrapping of text in a container?
5How do you make text responsive across different screen sizes?
6How do you justify text using CSS?
7What does text-shadow do? Give an example.
8How can you apply multiple shadows to text?
9How do you apply gradients to text in CSS?
10How do you control text overflow in a fixed-width container?
11What is the difference between em, rem, and px when styling text?
12How does font-weight differ from <b> tag in semantic meaning?
13How does accessibility relate to text formatting in HTML?
14What’s the difference between semantic and non-semantic text formatting tags?
15How can you ensure consistent text appearance across different browsers?
16What is the difference between font-style, font-variant, and font-weight?
17What is the role of @font-face in web typography?
18How can you import custom fonts in CSS?
19What’s the impact of using web fonts on performance?
20How can you optimise text rendering for readability?
21How do you make text appear vertically (top-to-bottom) using CSS?
22How do you style only the first letter or first line of a paragraph?
23How do you create a drop cap effect?
24How can you highlight a selected text range dynamically?
25How do you make text glow or have a neon effect using CSS?
26What CSS properties can you use for text animations?
27How can you apply a gradient background only to the text and not the entire element?
28How can you apply different styles to different words in the same line?
29How do you prevent text selection on a webpage?
30How do you implement responsive typography (fluid text size)?
09 / 30

How do you apply gradients to text in CSS?

Applying Gradients to Text in CSS

You can create visually appealing gradient-colored text in CSS using background-clip and text-fill-color properties along with a background gradient. The gradient is applied to the text instead of the element background.

Required CSS Properties
  1. 1

    background: linear-gradient(direction, color1, color2, ...); – Defines the gradient colors and direction.

  2. 2

    -webkit-background-clip: text; – Clips the background to the shape of the text (required for WebKit browsers).

  3. 3

    -webkit-text-fill-color: transparent; – Makes the text itself transparent so the gradient shows through.

Example: Gradient Text

In this example, the text displays a horizontal gradient from orange to peach. The -webkit-background-clip: text ensures the gradient only fills the letters, and -webkit-text-fill-color: transparent makes the underlying text color transparent to reveal the gradient.

Key Takeaways
  1. 1

    Gradient text requires background-clip: text and transparent text fill.

  2. 2

    WebKit prefixes (-webkit-) are necessary for cross-browser support, though modern browsers are increasingly supporting standard syntax.

  3. 3

    Combine with font-weight, font-size, and letter-spacing for striking typography.

  4. 4

    Can be layered with text shadows for more depth and visual interest.